# -*- coding: utf-8 -*-

# File Name : time_format
# Description :
# Author : marje
# date : 2022/6/7
# Change Activity : 2022/6/7
import time


class TimeFormat(object):
    @staticmethod
    def to_string(json_obj, key):
        """


        Args:
            json_obj:
            key:

        Returns:

        """
        if key in json_obj and json_obj[key] is not None:
            return str(json_obj[key])
        return ''

    @staticmethod
    def datetime_to_date_stamp(date_time):
        """

        Args:
            date_time:

        Returns:

        """
        time_array = time.strptime(date_time, "%Y-%m-%d %H:%M:%S")
        return int(time.mktime(time_array))

    @staticmethod
    def date_stamp_to_datetime(date_stamp):
        """

        :param date_stamp:
        :return:
        """
        date_stamp = int(date_stamp)
        time_local = time.localtime(date_stamp)
        dt = time.strftime("%Y-%m-%d %H:%M:%S", time_local)
        return dt

    @staticmethod
    def to_int(json_obj, key):
        """

        Args:
            json_obj:
            key:

        Returns:

        """
        if key in json_obj and json_obj[key] is not None:
            return int(json_obj[key])
        return 0

    @staticmethod
    def get_current_time():
        """

        Returns:

        """
        time_local = time.localtime(time.time())
        return time.strftime("%Y-%m-%d %H:%M:%S", time_local)

    @staticmethod
    def get_format_time():
        """

        Returns:

        """
        time_str = TimeFormat.get_current_time()
        return time_str.replace(' ', '-').replace(':', '-')
